const { Tag } = require("../database/sequlize");

// 获取所有标签
exports.getAllTags = async () => {
  return Tag.findAll();
};

// 获取单个标签通过id
exports.getTagById = async (tagId) => {
  return Tag.findByPk(tagId);
};

// 创建新的标签
exports.createTag = async (tagData) => {
  return Tag.create(tagData);
};

// 更新标签
exports.updateTag = async (tagId, tagData) => {
  const tag = await Tag.findByPk(tagId);
  if (!tag) {
    throw new Error("Tag not found");
  }
  return tag.update(tagData);
};

// 删除标签
exports.deleteTag = async (tagId) => {
  const tag = await Tag.findByPk(tagId);
  if (!tag) {
    throw new Error("Tag not found");
  }
  return tag.destroy();
};
